/*
package com.findviewbydream.evil.eda.Login;

import android.Manifest;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.dd.CircularProgressButton;
import com.findviewbydream.evil.eda.Bean.UserBean;
import com.findviewbydream.evil.eda.Data.Data;
import com.findviewbydream.evil.eda.R;
import com.findviewbydream.evil.eda.Utils.Encryp_AES;
import com.findviewbydream.evil.eda.Utils.Encryp_AES_E;
import com.findviewbydream.evil.eda.Utils.NetUtils;
import com.findviewbydream.evil.eda.Utils.PhoneUtils;
import com.findviewbydream.evil.eda.Utils.SAcp;
import com.findviewbydream.evil.eda.Utils.SuperToast.ButtonToast;
import com.findviewbydream.evil.eda.Utils.SuperToast.SuperToast;
import com.findviewbydream.evil.eda.Utils.Utils;
import com.orhanobut.logger.Logger;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.security.InvalidKeyException;
import java.util.HashMap;
import java.util.regex.Pattern;

import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK;
import cn.smssdk.utils.SMSLog;
import okhttp3.Call;

*/
/********************************************
 * 工程名：Eda
 * 包名：com.findviewbydream.evil.eda.Login
 * 时间：16-7-23 下午12:14
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：注册界面
 ********************************************//*

public class Register extends Login
{
    private Activity context;

    private ImageView pull_up;
    private ImageView register_background;


    private TextInputEditText userPhoneNum;
    private TextInputLayout userPhoneNum_Layout;
    private TextInputEditText identifyingCode;
    private TextInputLayout identifyingCode_Layout;
    private TextInputEditText userPassword;
    private TextInputLayout userPassword_Layout;

    private Button voice;
    private Button send;
    private CircularProgressButton submit;

    private EventHandler eventHandler;*/
/*短信验证码接收器*//*


    private int type = 0;*/
/*判断是提交手机号还是提交验证码,因为 提交失败 在同一处返回  0为手机号,1为验证码*//*


    public void onCreate(Activity context)
    {
        this.context = context;
        */
/*初始化短信验证码SDK*//*

        SMSSDK.initSDK(context, Data.SMSSDK_APP_KEY, Data.SMSSDK_APP_SECRET);
        setSMSSDK();

        initView();*/
/*初始化控件*//*

        initBackground();*/
/*初始化其他背景图*//*

        setPull_up();*/
/*上划登陆*//*

        setTextInputLayout();*/
/*设置输入框*//*

        setSendIdentifyingCode();*/
/*设置发送验证码按钮*//*

        setSubmit();*/
/*设置提交按钮*//*


        submit.setIndeterminateProgressMode(true);
    }

    */
/**
     * 初始化控件
     *//*

    private void initView()
    {
        pull_up = (ImageView) context.findViewById(R.id.pull_up);
        register_background = (ImageView) context.findViewById(R.id.register_background);
        userPhoneNum = (TextInputEditText) context.findViewById(R.id.register_userPhoneNum);
        userPhoneNum_Layout = (TextInputLayout) context.findViewById(R.id.register_userPhoneNum_Layout);
        identifyingCode = (TextInputEditText) context.findViewById(R.id.register_IdentifyingCode);
        identifyingCode_Layout = (TextInputLayout) context.findViewById(R.id.register_IdentifyingCode_Layout);
        userPassword = (TextInputEditText) context.findViewById(R.id.register_userPassword);
        userPassword_Layout = (TextInputLayout) context.findViewById(R.id.register_userPassword_Layout);
        voice = (Button) context.findViewById(R.id.register_voice);
        send = (Button) context.findViewById(R.id.register_send);
        submit = (CircularProgressButton) context.findViewById(R.id.register_submit);
    }

    */
/**
     * 初始化背景及其其他图片
     *//*

    private void initBackground()
    {
        Utils.Glide(R.drawable.login_background, register_background);
    }

    */
/**
     * 设置输入框
     *//*

    private void setTextInputLayout()
    {
        */
/*手机号*//*

        userPhoneNum_Layout.setHint("请输入手机号码,作为登陆账号使用");
        userPhoneNum.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
            {

            }

            @Override
            public void onTextChanged(CharSequence s, int i, int i1, int i2)
            {
                if (s.length() != 11)
                {
                    userPhoneNum_Layout.setError("请输入正确的手机号码!");
                    userPhoneNum_Layout.setErrorEnabled(true);
                }
                else
                    userPhoneNum_Layout.setErrorEnabled(false);
            }

            @Override
            public void afterTextChanged(Editable editable)
            {

            }
        });

        */
/*验证码*//*

        identifyingCode_Layout.setHint("请输入验证码");

        */
/*密码*//*

        userPassword_Layout.setHint("请输入密码");
        userPassword.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
            {

            }

            @Override
            public void onTextChanged(CharSequence s, int i, int i1, int i2)
            {
                if (s.length() > 20)
                {
                    userPassword_Layout.setError("密码过长!");
                    userPassword_Layout.setErrorEnabled(true);
                }
                else if (s.length() < 6)
                {
                    userPassword_Layout.setError("密码过短!");
                    userPassword_Layout.setErrorEnabled(true);
                }
                else
                    userPassword_Layout.setErrorEnabled(false);
            }

            @Override
            public void afterTextChanged(Editable editable)
            {

            }
        });
    }

    */
/**
     * 设置发送验证码按钮
     *//*

    private void setSendIdentifyingCode()
    {
        send.setText("发送验证码");
        send.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                type = 0;
                SMSSDK.getVerificationCode("+86", userPhoneNum.getText().toString());
                send.setClickable(false);
                new Utils.SHandler()
                {
                    private int time = 60;

                    @Override
                    public void thread(Handler handler)
                    {
                        for (int i = 60; i >= 0; i--)
                        {
                            time = i;
                            handler.sendEmptyMessage(0);
                            Utils.Threadsleep(1000);
                        }
                    }

                    @Override
                    public void handler()
                    {
                        if (time == 0)
                        {
                            send.setClickable(true);
                            send.setText("发送验证码");
                            voice.setVisibility(View.VISIBLE);
                        }
                        else
                            send.setText("再次发送" + time + "s");
                    }
                }.startByCustom();
            }
        });

        voice.setVisibility(View.INVISIBLE);
        voice.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                type = 0;
                SMSSDK.getVoiceVerifyCode("+86", userPhoneNum.getText().toString());
                voice.setText("请稍后……");
                voice.setClickable(false);
            }
        });
    }

    */
/**
     * 短信验证码
     *//*

    private void setSMSSDK()
    {
        eventHandler = new EventHandler()
        {
            private Handler handler = new Handler()
            {
                @Override
                public void handleMessage(Message msg)
                {
                    super.handleMessage(msg);
                    Bundle bundle = msg.getData();
                    String s = bundle.getString("des");
                    //Utils.ToastLong(s);
                    SuperToast.buttonToast(context)
                            .setBackgroundColor(ButtonToast.Background.RED)
                            .setText(s)
                            .show();

                    if (submit.getProgress() == 50)
                    {
                        submit.setProgress(-1);
                    }

                    if (NetUtils.isNetConnect(context))
                    {
                        if (type == 0)
                        {
                            userPhoneNum_Layout.setErrorEnabled(true);
                        }
                        else if (type == 1)
                        {
                            identifyingCode_Layout.setError("验证码输入错误");
                            identifyingCode_Layout.setErrorEnabled(true);
                        }
                    }
                }
            };

            @Override
            public void afterEvent(int event, int result, Object data)
            {
                if (result == SMSSDK.RESULT_COMPLETE)
                {
                    //回调完成
                    if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE)
                    {
                        //提交验证码成功
                        HashMap<String, Object> map = (HashMap<String, Object>) data;
                        Log.i("验证码", map.get("phone").toString());
                        if (map.get("phone").toString().equals(userPhoneNum.getText().toString()))
                        {
                            Utils.Log("验证成功");
                            afterSuccess();
                        }
                        else
                        {
                            submit.setProgress(-1);
                        }

                    }
                    else if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE)
                    {
                        //获取验证码成功
                        //Logger.e(data.toString());
                    }
                    else if (event == SMSSDK.EVENT_GET_VOICE_VERIFICATION_CODE)
                    {
                        //获取语音验证码成功
                        //Logger.i("获取验证码成功", data.toString());
                    }
                    else if (event == SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES)
                    {
                        //返回支持发送验证码的国家列表 中国86
                    }
                }
                else
                {
                    ((Throwable) data).printStackTrace();
                    Throwable throwable = (Throwable) data;
                    String des = null;
                    int status = 0;
                    try
                    {
                        JSONObject object = new JSONObject(
                                throwable.getMessage());
                        des = object.optString("detail");
                        status = object.optInt("status");
                        if (!TextUtils.isEmpty(des))
                        {
                            Bundle bundle = new Bundle();
                            bundle.putString("des", des);
                            Message message = new Message();
                            message.setData(bundle);
                            handler.sendMessage(message);
                        }
                    }
                    catch (JSONException e)
                    {
                        SMSLog.getInstance().w(e);
                    }
                    //Utils.Logger("失败" + des);
                }
            }
        };

        SMSSDK.registerEventHandler(eventHandler); //注册短信回调
    }

    */
/**
     * 设置提交按钮
     *//*

    private void setSubmit()
    {
        submit.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                */
/*登陆*//*

                if (submit.getProgress() == -1 || submit.getProgress() == 100)
                    submit.setProgress(0);
                else
                {
                    submit.setProgress(50);
                    type = 1;
                    SMSSDK.submitVerificationCode("+86"
                            , userPhoneNum.getText().toString()
                            , identifyingCode.getText().toString());

                    //afterSuccess();

                    */
/*其他操作等待验证码验证完成后操作*//*

                }
            }
        });
    }


    */
/**
     * 验证码完成后的操作
     *//*

    private void afterSuccess()
    {
        */
/*判断手机号码*//*

        if (userPhoneNum.getText().toString().length() != 11)
        {
            SuperToast.buttonToast(context)
                    .setBackgroundColor(ButtonToast.Background.RED)
                    .setText("请输入正确的手机号码")
                    .show();
            submit.setProgress(-1);
        }
        else if (userPassword.getText().toString().length() < 6
                || userPassword.getText().toString().length() > 20)
        {
            SuperToast.buttonToast(context)
                    .setBackgroundColor(ButtonToast.Background.RED)
                    .setText("请检查密码长度")
                    .show();
            submit.setProgress(-1);
        }
        else if (!Pattern.compile("[a-z0-9A-Z_]+")
                .matcher(userPassword.getText().toString()).matches())
        {
            SuperToast.buttonToast(context)
                    .setBackgroundColor(ButtonToast.Background.RED)
                    .setText("密码仅为数字、字母、下划线！")
                    .show();
            submit.setProgress(-1);
        }
        else
        {
            //toNetWork();
            getIMEI();*/
/*先获取到IMEI，才能联网，否则崩溃*//*

        }
    }

    */
/**
     * 获得IMEI
     * 获取权限
     *//*

    private void getIMEI()
    {
        new SAcp()
        {
            @Override
            public void onGranteds()
            {
                toNetWork();
            }

            @Override
            public void onDenieds()
            {
                SAcp.showDialog(context, context);
            }
        }.getPermissions(Manifest.permission.READ_PHONE_STATE);
    }

    */
/**
     * 网络加载
     *//*

    private void toNetWork()
    {
        OkHttpUtils.post()
                .url(Data.IP + "RegisterServlet")
                .addParams("type", "register")
                .addParams("userPhone", userPhoneNum.getText().toString())
                .addParams("userPassword"
                        , Encryp_AES.encryptCode(userPassword.getText().toString()))
                .addParams("imei", Utils.getIMEI())
                .build()
                .execute(new StringCallback()
                {
                    @Override
                    public void onError(Call call, Exception e, int id)
                    {
                        e.printStackTrace();
                        submit.setProgress(-1);
                        NetUtils.reportError(context, e);
                    }

                    @Override
                    public void onResponse(String response, int id)
                    {
                        if (response.equals("SUCCESS"))
                        {
                            submit.setProgress(100);
                        }
                        else if (response.equals("FAILE"))
                        {
                            SuperToast.buttonToast(context)
                                    .setBackgroundColor(ButtonToast.Background.RED)
                                    .setText("该手机号已经注册，请尝试登陆！")
                                    .show();
                            submit.setProgress(-1);
                        }
                        else if (response.equals("NOT_IN_HANDAN"))
                        {
                            SuperToast.buttonToast(context)
                                    .setBackgroundColor(ButtonToast.Background.RED)
                                    .setText("对不起，该手机号所在地不在邯郸")
                                    .show();
                            submit.setProgress(-1);
                        }
                    }
                });
    }

    */
/**
     * 下拉注册动画
     *//*

    private void setPull_up()
    {
        pull_up.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                Login.scrollView.smoothScrollTo(0, 0);
            }
        });

        Animation animation = new TranslateAnimation(0, 0, -50, 0);
        animation.setInterpolator(new AccelerateInterpolator());
        animation.setDuration(1000);
        animation.setRepeatMode(Animation.REVERSE);
        animation.setRepeatCount(Integer.MAX_VALUE);

        pull_up.startAnimation(animation);
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        SMSSDK.unregisterEventHandler(eventHandler);
    }
}
*/
